package com.gitee.wsl.mathematics.algebraic.sample

import com.gitee.wsl.mathematics.algebraic.Ring
import com.gitee.wsl.mathematics.algebraic.number.NumericAlgebra
import com.gitee.wsl.mathematics.algebraic.op.Norm
import kotlin.math.abs

interface Int64ExtendedField : Ring<Long>, Norm<Long, Long>, NumericAlgebra<Long>

/**
 * A field for [Double] without boxing. Does not produce an appropriate ring element.
 */
@Suppress("EXTENSION_SHADOWED_BY_MEMBER")
object Int64Ring :Int64ExtendedField{

    override val zero: Long get() = 0L
    override val one: Long get() = 1L

    override fun number(value: Number): Long = value.toLong()
    override fun add(left: Long, right: Long): Long = left + right
    override fun multiply(left: Long, right: Long): Long = left * right
    override fun norm(arg: Long): Long = abs(arg)

    override fun Long.unaryMinus(): Long = (-this)
    override fun Long.plus(arg: Long): Long = (this + arg)
    override fun Long.minus(arg: Long): Long = (this - arg)
    override fun Long.times(arg: Long): Long = (this * arg)
}

typealias LongRing = Int64Ring

val Long.Companion.algebra: Int64Ring get() = Int64Ring